﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DispatchAssist.Weather.Interfaces;
using DispatchAssist.Weather.Enums;

namespace DispatchAssist.Weather.Entities
{
    /// <summary>
    /// 天气图类型
    /// </summary>
    [Serializable]
    class WeatherMapType : IWeatherMapType
    {

        public static IWeatherMapType Empty = new WeatherMapType { Name = "无", WeatherMapTypeID = Guid.Empty };


        public Guid WeatherMapTypeID { get; set; }

        public Guid WeatherMapTypeParentID { get { return ParentType.WeatherMapTypeID; } }

        public string Name { get; set; }

        public Guid WeatherMapProviderID { get { return WeatherMapProvider.WeatherProvideID; } }

        public MapTypes MapType { get; set; }

        private IList<IWeatherMapInfo> infos;
        /// <summary>
        /// 天气图信息
        /// </summary>
        public IList<IWeatherMapInfo> Infos { get { return infos ?? (infos = new List<IWeatherMapInfo>()); } }
        private IWeatherMapType parentType;
        /// <summary>
        /// 父类型
        /// </summary>
        public IWeatherMapType ParentType
        {
            get { return parentType ?? Empty; }
            set
            {
                if (parentType == value)
                    return;

                if (parentType != null && parentType != Empty)
                {
                    parentType.ChildTypes.Remove(this);
                }

                if ((parentType == null || parentType == Empty))
                {
                    WeatherMapProvider.Types.Remove(this);
                }
                else if (value == null || value == Empty)
                {
                    if (!WeatherMapProvider.Types.Contains(this))
                        WeatherMapProvider.Types.Add(this);
                }

                if (value != null && value != Empty)
                    value.ChildTypes.Add(this);

                parentType = value;
            }
        }

        private IList<IWeatherMapType> childTypes;
        /// <summary>
        /// 子类型
        /// </summary>
        public IList<IWeatherMapType> ChildTypes { get { return childTypes ?? (childTypes = new List<IWeatherMapType>()); } }

        public IWeatherMapProvider WeatherMapProvider { get; private set; }

        private WeatherMapType() { }

        public WeatherMapType(IWeatherMapProvider mapProvider, IWeatherMapType parentType)
        {
            WeatherMapProvider = mapProvider;
            ParentType = parentType;
        }

    }
}
